﻿using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
using System.Text;
using System;

public class ReadSmsFromBluetooth
{
    public static void test()
    {
        var bluetooth = new BluetoothClient();
        foreach (var device in bluetooth.PairedDevices)
        {
            Console.WriteLine(device.DeviceName);
            Console.WriteLine(device.ClassOfDevice);
            bluetooth.Connect(device.DeviceAddress, BluetoothService.Handsfree); // 或者其他适合通信的服务
            var stream = bluetooth.GetStream();
            Console.WriteLine(stream.CanRead);
            if (stream.CanRead)
            {
                byte[] buffer = new byte[1024];
                int length = stream.Read(buffer, 0, buffer.Length);
                Console.WriteLine(length);
                string sms = Encoding.UTF8.GetString(buffer, 0, length);
                Console.WriteLine(sms);
            }
        }
    }
}